home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / newsgroups / misc.19981211-19990422 / 000382_news@watsun.cc.columbia.edu _Fri Mar 19 11:45:32 1999.msg < prev    next >
Internet Message Format  |  2020-01-01  |  2KB

  1. Return-Path: <news@watsun.cc.columbia.edu>
  2. Received: from newsmaster.cc.columbia.edu (newsmaster.cc.columbia.edu [128.59.59.30])
  3.     by watsun.cc.columbia.edu (8.8.5/8.8.5) with ESMTP id LAA14134
  4.     for <kermit.misc@watsun.cc.columbia.edu>; Fri, 19 Mar 1999 11:45:31 -0500 (EST)
  5. Received: (from news@localhost)
  6.     by newsmaster.cc.columbia.edu (8.8.5/8.8.5) id LAA20625
  7.     for kermit.misc@watsun.cc.columbia.edu; Fri, 19 Mar 1999 11:43:01 -0500 (EST)
  8. X-Authentication-Warning: newsmaster.cc.columbia.edu: news set sender to <news> using -f
  9. From: dn5006@my-dejanews.com
  10. Subject: Associative Array in Kermit 95
  11. Date: Fri, 19 Mar 1999 16:27:07 GMT
  12. Organization: Deja News - The Leader in Internet Discussion
  13. Message-ID: <7cttsc$47f$1@nnrp1.dejanews.com>
  14. To: kermit.misc@watsun.cc.columbia.edu
  15.  
  16. Associative array is a very useful feature in scripting language, it enables
  17. Perl, Tcl etc. the implementation of comlex data structures.
  18. The following script demonstrates that associative array can also be crafted
  19. in Kermit 95. The script counts the unique words in a regular english, french,
  20. german, etc. text file.
  21.  
  22. open read testfile.txt
  23. if fail end 1 Can't not open testfile.txt
  24. assign \%n 0            ; init register
  25. while true {
  26.     read \%l        ; read each line
  27.     if fail break   ; until the end of file
  28.     while > \flength(\%l) 0 {
  29.         assign \%w \fbreak(\%l,{ })               ; split on space
  30.         xif defined \m(\%w) {                     ; word already seen?
  31.             _assign \%w \feval(\m(\%w) + 1)   ; incr count this word
  32.         } else {
  33.             _assign \%w 1                     ; init count this word
  34.             increment \%n                     ; next register
  35.             _assign \%n \%w                   ; register this word
  36.         }
  37.         assign \%l \fltrim(\fright(\%l,\feval(\flength(\%l) - \flength
  38. (\%w))))  ; shift to next word
  39.     }
  40. }
  41.  
  42. for \%k 1 \%n 1 {
  43.     assign \%w \m(\%k)    ; get word from register
  44.     echo <\m(\%w)> \%w    ; display occurences
  45. }
  46.  
  47. This approach avoids the use of array which has to be declared in advance.
  48. The script does not take into account the non alphanumeric characters.
  49.  
  50. Dat Nguyen
  51. Airline Telecommunications and Information Services
  52. 770 Sherbrooke West
  53. Montreal, Quebec
  54. Canada H3A 1G1
  55. Email dat.nguyen&sita.int
  56.  
  57. -----------== Posted via Deja News, The Discussion Network ==----------
  58. http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own